import { useRequest } from 'umi';
import {
  queryDoorDeviceStatusAPI,
  queryOpenRecordChartAPI,
  queryOpenRecordPieAPI,
  queryAlarmDoorListAPI,
  queryRunAlarmAPI,
  queryOpenRecordCountAPI,
} from './services';
import { createModel } from 'hox';
import { useState } from 'react';
import { DataNode } from 'antd/lib/tree';
import { queryRunAlarmPieAPI } from '../Alarm/services';
type AreaListProps = DataNode & { code?: string };
interface HoxModelProps {
  areaList: AreaListProps[];
  selectedKeys: string[];
  currentCode: string;
}
function useHoxModel() {
  const [state, setState] = useState<HoxModelProps>({
    areaList: [],
    selectedKeys: [],
    currentCode: '',
  });
  const dispatch = (payload: Partial<HoxModelProps>) => {
    setState((pre) => ({ ...pre, ...payload }));
  };

  //开门记录
  const {
    run: getOpenRecordChart,
    data: openRecordChart,
    loading: openRecordChartLoading,
  } = useRequest(queryOpenRecordChartAPI, {
    manual: true,
  });
  //设备状态
  const {
    run: getDoorDeviceStatus,
    data: doorDeviceStatus,
    loading: doorDeviceStatusLoading,
  } = useRequest(queryDoorDeviceStatusAPI, {
    manual: true,
  });
  //设备状态
  const { run: getOpenRecordPie, data: openRecordPie, loading: openRecordPieLoading } = useRequest(
    queryOpenRecordPieAPI,
    {
      manual: true,
    },
  );
  //获取告警排行
  const { run: getAlarmDoorList, data: alarmDoorList, loading: alarmDoorListLoading } = useRequest(
    queryAlarmDoorListAPI,
    {
      manual: true,
    },
  );
  //获取实时告警
  const { run: getRunAlarm, data: runAlarmList, loading: runAlarmLoading } = useRequest(
    queryRunAlarmAPI,
    {
      manual: true,
    },
  );
  //获取实时告警
  const {
    run: getOpenRecordCount,
    data: openRecordCount,
    loading: openRecordCountLoading,
  } = useRequest(queryOpenRecordCountAPI, {
    manual: true,
  });
  //获取实时告警饼图图表
  const { run: getRunAlarmPie, data: runAlarmPie, loading: runAlarmPieLoading } = useRequest(
    queryRunAlarmPieAPI,
    {
      manual: true,
    },
  );
  return {
    ...state,
    dispatch,
    //
    getRunAlarmPie,
    runAlarmPie,
    runAlarmPieLoading,
    getRunAlarm,
    runAlarmList,
    openRecordCountLoading,
    openRecordCount,
    getOpenRecordCount,
    runAlarmLoading,
    alarmDoorList,
    alarmDoorListLoading,
    getAlarmDoorList,
    getOpenRecordPie,
    openRecordPie,
    openRecordPieLoading,
    openRecordChartLoading,
    getOpenRecordChart,
    openRecordChart,
    getDoorDeviceStatus,
    doorDeviceStatus,
    doorDeviceStatusLoading,
  };
}
export default createModel(useHoxModel);
